import { addOrgService, deleteOrgService, getOrgListService } from '../../../model/service/orgManage/index';

// 添加机构信息
export async function addOrg(ctx: Context, next: Next): Promise<void> {
  const { body } = ctx.request;
  try {
    const result = await addOrgService(body);
    ctx.api.success(result, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}

// 删除机构信息
export async function deleteOrg(ctx: Context, next: Next): Promise<void> {
  const { url } = ctx.request.body;
  try {
    ctx.api.success({}, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}

// 更新机构信息
export async function updateOrg(ctx: Context, next: Next): Promise<void> {
  const { url } = ctx.request.body;
  try {
    ctx.api.success({}, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}

// 获取机构信息列表
export async function getOrgList(ctx: Context, next: Next): Promise<void> {
  const { uid } = ctx.request.body;
  console.log(uid, '.....')
  try {
    const result = await getOrgListService(uid);
    ctx.api.success(result, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}